/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/
/*
Authors: Ram Ovadia 201374022 and Lior Fass 300069705
Project: HW Assignment 2 
Description: This is the header of the utility module holding the types and functions declarations used by VersionControl.c.  
*/
/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef VS_UTILS_H
#define VS_UTILS_H

#include <stdio.h>
#include <tchar.h>
#include "windows.h"

#define _CRT_SECURE_NO_WARNINGS

#define ARGS 4
#define INPUT_ARG 1
#define ORDER_ARG 2
#define TIMEOUT_ARG 3
#define OUTPUT_ARG 4
#define NUM_OF_EXES 4

//typedef enum {FALSE, TRUE} BOOL;
typedef enum {serial = 0, parallel} order_t;

// const strings for string compares
const char* serial_str;
const char* parallel_str;
const char* txtfile_str;
const char * folder;
const char * exe_suffix;

const char * exes[];

const char * output_strs[];
const char * timeout_str;

/*
 * check that file exists, and that it is not a directory. 
 * 
 * Input:
 * -----
 * path - a string contains the file path 
 *
 * Output:
 * -----
 * Return Value:
 * TRUE if  file exists and if it's not a dir, else FALSE.
 */
BOOL isFile(LPCTSTR path);


/*
 * check that all chars are valid digit in the range 0-9 
 * 
 * Input:
 * -----
 * str - pointer to array of chars. 
 *
 * Output:
 * -----
 * Return Value:
 * TRUE if all digits are numbers, else FALSE.
 */
BOOL isInteger(char *str);


/*
 * Builds command line for CreateProcessSimple function 
 * 
 * Input:
 * -----
 * exeNum - int in the range 0-3 that picks one of 4 available exe
 * line - string contains file name to be checked with the requested exe
 *
 * Output:
 * -----
 * Return Value:
 * pointer to string contains the command line.
 */
char * BuildCommand( int exeNum,const char * line);


/*
 * wrap to CreateProcess function with default Params. 
 * 
 * Input:
 * -----
 * CommandLine - string contains the exe name and its arguments
 * ProcessInfoPtr - a pointer to PROCESS_INFORMATION, it's values are irrelevant.
 *
 * Output:
 * -----
 * ProcessInfoPtr - this struct will be filled by CreateProcess function
 * Return Value:
 * TRUE if process created successfully, else FALSE 
 */
BOOL CreateProcessSimple( LPTSTR CommandLine, PROCESS_INFORMATION *ProcessInfoPtr );


/*
 * convert a string to lowercase using toLower fucntion 
 * 
 * Input:
 * -----
 * pStr - pointer to string contains both upper case and lower case letters
 *
 * Output:
 * -----
 * pStr - the string chars are modified to be all lowercase 
 */
void StringToLower( char *pStr);


/*
 * write summary line to output file, and close file handles 
 * 
 * Input:
 * -----
 * passFlag - string contains the exe name and its arguments
 * hInFile/hOutFile - handles to input and output text files
 *
 * Output:
 * -----
 * write summary line to hOutFile
 */
void finalizeRun(BOOL passFlag, FILE *hInFile, FILE *hOutFile);


/*
 * Close handles to threads and process of all files, and initialize ProcInfo Struct
 * 
 * Input:
 * -----
 * ProcInfo - array of structs contains 4 process one for each exe
 * timeout_exceeded - array of flags of timeouts, to be initialized
 * lpHandles - array of processes handles to be initialized
 *
 * Output:
 * -----
 * handles are closed, pointers initialized to NULL, timeout initialized to 0
 */
void closeAllHandles(PROCESS_INFORMATION ProcInfo[], int timeout_exceeded[], HANDLE lpHandles[]);


/*
 * Initialize array of process info structs 
 * 
 * Input:
 * -----
 * ProcInfo - array of 4 process information structs
 *
 * Output:
 * -----
 * the array ProcInfo pointers initialized to NULL and values to zero
 */
void initializeProcInfo(PROCESS_INFORMATION ProcInfo[]);

#endif // VS_UTILS_H